<?
if (!defined('MODULE_FILE')){
	die ("cant access file directly!");
}

$mid 	= ( ( true == isset( $_GET['mid'] ) && true == valStr( $_GET['mid'] ) ) ? $_GET['mid'] : NULL );
$smid 	= ( ( true == isset( $_GET['smid'] ) && true == valStr( $_GET['smid'] ) ) ? $_GET['smid'] : NULL );

autoLoader();

$objBaseEmployees 	= new BaseEmployees();
$objEmployees 	= new Employees();
$objDepartments      = new Departments();
$objEmployeeTypes         = new EmployeeTypes();
?>
<html>
<head>
<?php require_once 'commonJS.php'; ?>
</head>
<body>
	<div style="margin-left:12px; margin-top: 10px;">
		<p>
			<a class="btn btn-outline btn-primary btn-xs" id="act" href="modules.php?file=employees&mid=<? echo $mid;?>&smid=<? echo $smid;?>" >Add New Employees</a>
			<a class="btn btn-outline btn-primary btn-xs" id="active" href="modules.php?file=view_employees&type=view&mid=<? echo $mid;?>&smid=<? echo $smid;?>" >View All Employees</a>&nbsp;
		</p>
	</div>
<div class="col-lg-8">
<div class="panel panel-primary">
<div class="panel-heading"><i class="fa fa-bell fa-fw"></i> Employees</div>
<div class="panel-body">
	<form METHOD="POST" action="modules.php?file=insert_employees&type=insert&mid=<? echo $mid; ?>&smid=<? echo $smid; ?>" id="formSubmit" name="formSubmit" >
		<?php
		$intEmpId = NULL;
		$intDepartmentId =NULL;
		$intEmployeeTypeId=NULL;
		$strFirstName=NULL;
		$strMiddleName=NULL;
		$strLastName=NULL;
		$strPhoneNumber=NULL;
		$strMobileNumber=NULL;
		$strOfficeNumber=NULL;
		$strEmailAddress=NULL;
		$strAddressLine1=NULL;
		$strAddressLine2=NULL;
		$strArea=NULL;
		$strCity=NULL;
		$strPinCode=NULL;
	
				
		if( true == isset( $_GET['employee_id'] ) && true == valStr( $_GET['employee_id'] ) ) {
			$intEmpId = $_GET['employee_id'];
			
			$objBaseEmployees = $objEmployees->fetchEmployeesById( $_GET['employee_id'] );
			
			if( true == valObj( $objBaseEmployees, 'BaseEmployees' ) ) {
				$intDepartmentId 	= $objBaseEmployees->getDepartmentId();
				$intEmployeeTypeId 	= $objBaseEmployees->getEmployeeTypeId();
				$strFirstName 		= $objBaseEmployees->getFirstName();
				$strMiddleName 		= $objBaseEmployees->getMiddleName();
				$strLastName 		= $objBaseEmployees->getLastName();
				$strPhoneNumber 	= $objBaseEmployees->getPhoneNumber();
				$strMobileNumber 	= $objBaseEmployees->getMobileNumber();
				$strOfficeNumber 	= $objBaseEmployees->getOfficeNumber();
				$strEmailAddress 	= $objBaseEmployees->getEmailAddress();
				$strAddressLine1 	= $objBaseEmployees->getAddressLine1();
				$strAddressLine2 	= $objBaseEmployees->getAddressLine2();
				$strArea 		    = $objBaseEmployees->getArea();
				$strCity 		    = $objBaseEmployees->getCity();
				$strPinCode 		= $objBaseEmployees->getPinCode();
			}
		} else if( true == valObj( $objBaseEmployees, 'BaseEmployees' ) ) {
			$intEmpId = $objBaseEmployees->fetchNextId();
		}
		?> 
	
		<table width="80%" cellspacing="0" cellpadding="3">

			<tr><td height="10" colspan="2" width="220"><input id="employee_id" Name="employee_id" type="hidden"  style="width:100px;"  value="<?php echo $intEmpId;?>"></td></tr>
          	<tr valign="top">
				<td  width="220">Department</td>
				<td>
		        <select class="validate[required]" name="department_id" id="department_id" style="width:202px;">
				<option value=''>-Select-</option>
				<?php
					$arrobjDepartments = $objDepartments->fetchAllDepartments();
					
					if( true == valStr( $arrobjDepartments ) ) {
						foreach( $arrobjDepartments as $Department ) {
							echo '<option' . ( ( $intDepartmentId == $Department->getId() ) ? ' selected' : '' ) . ' value=' . $Department->getId() . '>' . $Department->getName() . '</option>';
						}
					}
					?>
				</select>
				</td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			 	<tr valign="top">
				<td  width="220">Employee Type</td>
				<td>
		        <select class="validate[required]" name="employee_type_id" id="employee_type_id" style="width:202px;">
				<option value=''>-Select-</option>
				<?php
					$arrobjEmployeeTypes = $objEmployeeTypes->fetchAllEmployeeTypes();
					
					if( true == valStr( $arrobjEmployeeTypes ) ) {
						foreach( $arrobjEmployeeTypes as $EmployeeType ) {
							echo '<option' . ( ( $intEmployeeTypeId == $EmployeeType->getId() ) ? ' selected' : '' ) . ' value=' . $EmployeeType->getId() . '>' . $EmployeeType->getName() . '</option>';
						}
					}
					?>
				</select>
				</td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			 <tr valign="top">
				<td  width="220">First Name</td>
				<td><input id="first_name" Name="first_name" type="text" class="validate[required]" value="<?php echo $strFirstName;?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			 <tr valign="top">
				<td  width="220">Middle Name</td>
				<td><input id="middle_name" Name="middle_name" type="text" class="validate[required]" value="<?php echo $strMiddleName;?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td  width="220">Last Name</td>
				<td><input id="last_name" Name="last_name" type="text" class="validate[required]" value="<?php echo $strLastName;?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td  width="220">Phone Number</td>
				<td><input id="phone_number" Name="phone_number" type="text" value="<?php echo $strPhoneNumber;?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td  width="220">Mobile Number</td>
				<td><input id="mobile_number" Name="mobile_number" type="text" class="validate[required]" value="<?php echo $strMobileNumber;?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td  width="220">Office Number</td>
				<td><input id="office_number" Name="office_number" type="text" value="<?php echo $strOfficeNumber;?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td  width="220">E-mail Address</td>
				<td><input id="email_address" Name="email_address" type="text" value="<?php echo $strEmailAddress;?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td  width="220">Address Line 1</td>
				<td><textarea name="address_line1" rows="5" cols="40"><?php echo $strAddressLine1;?></textarea></td>
				
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			 <tr valign="top">
				<td  width="220">Address Line 2</td>
				<td><textarea name="address_line2" rows="5" cols="40"><?php echo $strAddressLine2;?></textarea></td>
			</tr>
				<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			 <tr valign="top">
				<td  width="220">Area</td>
				<td><input id="area" Name="area" type="text" value="<?php echo $strArea;?>" style="width:202px;"></td>
			</tr>
				<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			 <tr valign="top">
				<td  width="220">City</td>
				<td><input id="city" Name="city" type="text" value="<?php echo $strCity;?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			 <tr valign="top">
				<td  width="220">Pin Code</td>
				<td><input id="pin_code" Name="pin_code" type="text" value="<?php echo $strPinCode;?>" style="width:202px;"></td>
			</tr>
			
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td class="mandatory" width="220">&nbsp;</td>
				<td>
				<?php
					if( true == isset( $_GET['employee_id'] ) && true == valStr( $_GET['employee_id'] ) ) {
						echo "<input type=hidden name=operation value=update>";
						echo "<input type=submit value=UPDATE id=Submit name=Submit>";
					} else {
						echo "<input type=hidden name=operation value=insert>";
						echo "<input type=submit value=SUBMIT id=Submit name=Submit>";
					}
					?>
				
				</td> 				
			</tr>
		</table>
</div>
</div>
</div>	
</form>
</body>
</html>